<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2021/5/13
  Time: 15:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    //获取项目的根路径
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<html>
<head>
    <meta charset="utf-8">
    <title>医生增删改查页面</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

    <link rel="stylesheet" href="<%=basePath%>static/layui-v2.6.5/layui/css/layui.css">
    <link rel="stylesheet" href="<%=basePath%>static/drug/drugyan/css/drugSelect.css">
    <link rel="stylesheet" type="text/css" href="<%=basePath%>static/swee/sweetalert.css">
    <script type="text/javascript" src="<%=basePath%>static/swee/sweetalert-dev.js"></script>
    <script src="<%=basePath%>static/jquery/jquery-1.12.4.js"></script>

    <style>
        #yingchang {
            width: 500px;
            height: 510px;
            background-color: white;
            opacity: 0.9;
            border-radius: 5%;
            border: 1px solid rgb(70, 200, 200);
            position: absolute;
            top: 10%;
            left: 30%;
        }

        #yingchang2 {
            width: 500px;
            height: 510px;
            background-color: white;
            opacity: 0.9;
            border-radius: 5%;
            border: 1px solid rgb(70, 200, 200);
            position: absolute;
            top: 10%;
            left: 30%;
        }
        #yingchang3 {
            width: 1500px;
            height: 510px;
            background-color: white;
            opacity: 0.9;
            border-radius: 5%;
            border: 1px solid rgb(70, 200, 200);
            position: absolute;
            top: 10%;
        }

        .newinput {
            margin-top: 10px;
            border: none;
            border-bottom: 1.5px solid #009f95;
            margin-left: 10px;
            height: 30px;
        }

        .ppp {
            margin-top: 20px;
            margin-left: 80px;
            width: 430px;
            height: 500px;
        }
    </style>
</head>
<body>
<div id="head" style="height: 600px">
    <ul>
        <li style="width: 100%;  ">
            <div class="head_below1" style="width: 100%;margin-top: 30px">
                <h2 style="font-size: 40px">华子医院人员管理页面</h2>
                <div>
                <form style="display: inline-block" action="<%=basePath%>doctorY/doctorPage" method="post" style="margin-left: 300px">
                    <p style="display: inline-block">请输入姓名:<input type="text" name="name" placeholder="请输入姓名" class="input1">
                        <button type="submit" class="layui-btn" style="margin-left: 20px">查询</button>
                        <span style="color: #009f95;font-size: 25px;font-weight: bold;margin-left: 100px">点我新增--></span>
                        <button type="button" class="layui-btn" id="xingzeng">新增医生</button>

                    </p>
                </form >
                    <button type="button" class="layui-btn" onclick="lizhi()" id="lizhi">离职医生信息</button>

                </div>
                <%--存放查询结果--%>
                <div class="layui-form" style="margin-top: 20px">
                    <table class="layui-table" style="font-size: 10px">
                        <thead>
                        <tr>
                            <td>编号</td>
                            <td>姓名</td>
                            <td>性别</td>
                            <td>年龄</td>
                            <td>所属科种</td>
                            <td>身份证号</td>
                            <td>电话</td>
                            <td>级别</td>
                            <td>所属科室</td>
                            <td>毕业学校</td>
                            <td>入职日期</td>
                            <td>操作</td>
                        </tr>
                        </thead>
                        <tbody>
                        <c:forEach items="${page.list}" var="doctor">
                            <tr>
                                <td>${doctor.doctorId}</td>
                                <td>${doctor.doctorname}</td>
                                <td>${doctor.doctorSex}</td>
                                <td>${doctor.doctorAge}</td>
                                <td>${doctor.doctorke}</td>
                                <td>${doctor.doctorcard}</td>
                                <td>${doctor.doctorphone}</td>
                                <td>${doctor.position}</td>
                                <td>${doctor.type}</td>
                                <td>${doctor.doctorType}</td>
                                <td>${doctor.doctorDate}</td>
                                <td>
                                    <span><button type="button" class="layui-btn">编辑</button></span>
                                    <label>
                                        <button type="button" class="layui-btn">删除</button>
                                    </label>
                                    <button type="button" class="layui-btn" onclick="pb('${doctor.doctorId}','${doctor.type}','${doctor.position}')">排班</button>
                                </td>
                            </tr>
                        </c:forEach>
                        </tbody>
                    </table>
                    <p style="text-align: center">
                        <c:choose>
                        <c:when test="${page.list.size()>0}">

                        <a href="<%=basePath%>doctorY/doctorPage?pageNum=${page.firstPage}&name=${name}">首页</a>
                        <a href="<%=basePath%>doctorY/doctorPage?pageNum=${page.prePage}&name=${name}">上一页</a>
                        <a href="<%=basePath%>doctorY/doctorPage?pageNum=${page.nextPage}&name=${name}">下一页</a>
                        <a href="<%=basePath%>doctorY/doctorPage?pageNum=${page.lastPage}&name=${name}">末页</a>

                        <span>第${page.pageNum}页/共${page.pages}页(${page.total}条记录)</span>

                        </c:when>
                        <c:otherwise>
                    <h2 style="text-align: center">没找到您需要的信息！</h2>
                    </c:otherwise>
                    </c:choose>
                    </p>
                </div>
            </div>
        </li>
    </ul>
</div>
<div id="yingchang" style="display: none">
    <form>
        <p id="biaoti" style="color: #009f95;font-weight: bold;font-size: 30px;margin-top: 10px;margin-left: 105px">
            华子医院医生新增页面 <img
                src="<%=basePath%>static/img/cuowu.png" style="width: 30px;margin-left: 30px" class="imgcilck"></p>
        <div class="inputTijiao" style="font-family: 微软雅黑">
            <p>姓&nbsp; &nbsp; &nbsp; 名：<input type="text" value="" placeholder="请输入姓名" class="input1"
                                              style="width: 200px;" id="name"></p>
            <p style="margin-top: 10px">
                性&nbsp; &nbsp; &nbsp; 别：
                <input type="radio" value="男" name="sex" checked>男
                <input type="radio" value="女" name="sex" style="margin-left:20px">女

                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;年&nbsp; &nbsp; &nbsp; 龄:<input type="text" value=""
                                                                                        placeholder="年龄" id="age"
                                                                                        class="input1"
                                                                                        style="width: 50px">
            </p>
            <p style="margin-top: 10px">
                所属科种
                <select name="interest1" class="input1" id="kezhong">
                    <option value="内科" selected="selected">内科</option>
                    <option value="外科">外科</option>
                </select>
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 所属科室
                <select name="interest2" class="input1" id="keshi">
                    <option value="神经外科">神经外科</option>
                    <option value="骨科">骨科</option>
                    <option value="华子科">华子科</option>
                </select>
            </p>
            <p>
                电&nbsp; &nbsp; &nbsp; 话: <input type="text" value="" placeholder="请输入电话" id="phone" class="input1"
                                                style="width: 200px;">
            </p>
            <p>
                身份证号:<input type="text" value="" id="shengfeng" placeholder="请输入身份证号" class="input1"
                            style="width: 250px;">
            </p>
            <p style="margin-top: 10px">
                级&nbsp; &nbsp; &nbsp;&nbsp;别:
                <select name="interest3" style="width: 150px" class="input1" id="jibie">
                    <option value="主治医师">主治医师</option>
                    <option value="主任医生">主任医生</option>
                    <option value="金牌性感医生">金牌性感医生</option>
                    <option value="神医">神医</option>
                </select>
            </p>
            <p style="margin-top: 10px">
                毕业学校:<input type="text" value="" id="school" placeholder="请输入" class="input1" style="width: 200px;">
            </p>
            <p>
                入职日期:<input type="date" value="" id="dateRiqi" placeholder="请输入" class="input1" style="width: 200px;">
            </p>
            <p style="margin-top: 15px;margin-left: 170px">
                <button type="button" class="layui-btn" id="quxiao">取消</button>
                <button type="button" class="layui-btn" id="queren" style="margin-left: 40px">确认</button>
            </p>
        </div>
    </form>
</div>

<div id="yingchang2" style="display: none">
    <form>
        <p id="biaoti2" style="color: #009f95;font-weight: bold;font-size: 30px;margin-top: 10px;margin-left: 105px">
            华子医院医生修改页面 <img
                src="<%=basePath%>static/img/cuowu.png" style="width: 30px;margin-left: 30px" class="imgcilck2"></p>
        <div class="inputTijiao" style="font-family: 微软雅黑">
            <p>姓&nbsp; &nbsp; &nbsp; 名：<input type="text" value="" placeholder="请输入姓名" class="input1"
                                              style="width: 200px;" id="name2"></p>
            <p style="margin-top: 10px">
                性&nbsp; &nbsp; &nbsp; 别：<input type="radio" value="男" name="sex" checked="checked">男<input
                    type="radio" value="女" name="sex" style="margin-left:20px">女
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;年&nbsp; &nbsp; &nbsp; 龄:<input type="text" value=""
                                                                                        placeholder="年龄" id="age2"
                                                                                        class="input1"
                                                                                        style="width: 50px">
            </p>
            <p style="margin-top: 10px">
                所属科种
                <select name="interest1" class="input1" id="kezhong2">
                    <option value="内科" selected="selected">内科</option>
                    <option value="外科">外科</option>
                </select>
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 所属科室
                <select name="interest2" class="input1" id="keshi2">
                    <option value="神经外科">神经外科</option>
                    <option value="骨科">骨科</option>
                    <option value="华子科">华子科</option>
                </select>
            </p>
            <p>
                电&nbsp; &nbsp; &nbsp; 话: <input type="text" value="" placeholder="请输入电话" id="phone2" class="input1"
                                                style="width: 200px;">
            </p>
            <p>
                身份证号:<input type="text" value="" id="shengfeng2" placeholder="请输入身份证号" class="input1"
                            style="width: 250px;">
            </p>
            <p style="margin-top: 10px">
                级&nbsp; &nbsp; &nbsp;&nbsp;别:
                <select name="interest3" style="width: 150px" class="input1" id="jibie2">
                    <option value="主治医师">主治医师</option>
                    <option value="主任医生">主任医生</option>
                    <option value="金牌性感医生">金牌性感医生</option>
                    <option value="神医">神医</option>
                </select>
            </p>
            <p style="margin-top: 10px">
                毕业学校:<input type="text" value="" id="school2" placeholder="请输入" class="input1" style="width: 200px;">
            </p>
            <p>
                入职日期:<input type="text" value="" id="dateRiqi2" placeholder="请输入" class="input1" style="width: 200px;">
            </p>
            <p style="margin-top: 15px;margin-left: 170px">
                <button type="button" class="layui-btn" id="quxiao2">取消</button>
                <button type="button" class="layui-btn" id="queren2" style="margin-left: 40px">确认</button>
            </p>
        </div>
    </form>
</div>

<%--存放查询结果--%>
<div id="yingchang3" style="display: none">
<div class="layui-form" id="lzxx" style="margin-top: 20px;">

    <table class="layui-table" style="font-size: 10px">
        <thead>
        <tr>
            <td>编号</td>
            <td>姓名</td>
            <td>性别</td>
            <td>年龄</td>
            <td>所属科种</td>
            <td>身份证号</td>
            <td>电话</td>
            <td>级别</td>
            <td>所属科室</td>
            <td>毕业学校</td>
            <td>入职日期</td>
            <td>离职日期</td>
        </tr>
        </thead>
     <tbody id="nr">

     </tbody>
    </table>
   <p style="text-align: center">
        <button type="button" class="layui-btn" id="gb" style="margin-left: 40px">关闭</button>
    </p>
</div>
</div>
</body>
</html>

<script type="text/javascript">

    $("#gb").click(function () {
        $("#yingchang3").hide();
    })

    function lizhi(){
        $("#yingchang3").show();
        $.ajax({
            //请求方式
            type: 'post',
            url: '<%=basePath%>doctorY/lizhi',
            dataType: 'json',
            success: function (data) {
                console.log(data);
                //获取需要的数据

                //拼接字符串
                let str = ``;

                //对数据做遍历，拼接到页面显示
                for (var i = 0; i < data.length; i++) {
                    str+=`<tr>
                         <td>\${data[i].doctorId}</td>
                         <td>\${data[i].doctorname}</td>
                         <td>\${data[i].doctorSex}</td>
                         <td>\${data[i].doctorAge}</td>
                         <td>\${data[i].doctorke}</td>
                         <td>\${data[i].doctorcard}</td>
                         <td>\${data[i].doctorphone}</td>
                         <td>\${data[i].position}</td>
                         <td>\${data[i].type}</td>
                         <td>\${data[i].doctorType}</td>
                         <td>\${data[i].doctorDate}</td>
                         <td>\${data[i].doctorResign}</td>
                         </tr>`;
                }

                console.log("输出："+str)

                //放入页面的容器显示
                $('#nr').html(str);

            }
    })
    }

        let array = new Array();
        let array2 = new Array(11);
        let array3 = new Array();
        $(document).ready(function () {

            $("#yingchang").hide();
            $("#yingchang2").hide();
            $("#yingchang3").hide();
            $("#xingzeng").click(function () {
                $("#yingchang").show();
                qingkong();
                $(".inputTijiao").addClass("ppp");
                $(".input1").addClass("newinput");
            });

            $(".imgcilck").click(function () {
                $("#yingchang").hide();
            });
            $(".imgcilck2").click(function () {
                $("#yingchang2").hide();
            });
            $("#quxiao").click(function () {
                $("#yingchang").hide();
            });
            $("#quxiao2").click(function () {
                $("#yingchang2").hide();
            });

            //更新
            $("tbody tr td span").click(function () {

                $("#yingchang2").show();
                $(".inputTijiao").addClass("ppp");
                $(".input1").addClass("newinput");
                let count = 0;
                $(this).parent().parent().children("td").each(function () {
                    array2[count] = $(this).text();
                    count++;
                });
                $("#name2").val(array2[1]);

                //动态设置单选框的选中
                if (array2[2] == "男") {

                    $("#yingchang2 input[name='sex']:eq(0)").prop("checked", true);
                    $("#yingchang2 input[name='sex']:eq(1)").prop("checked", false);

                } else {
                    $("#yingchang2 input[name='sex']:eq(0)").prop("checked", false);
                    $("#yingchang2 input[name='sex']:eq(1)").prop("checked", true);
                }

                $("#age2").val(array2[3]);
                $("#kezhong2").val(array2[4]);
                $("#shengfeng2").val(array2[5]);
                $("#phone2").val(array2[6]);
                $("#jibie2").val(array2[7]);
                $("#keshi2").val(array2[8]);
                $("#school2").val(array2[9]);
                $("#dateRiqi2").val(array2[10]);

            })

            //删除
            $("tbody tr td label").click(function () {
                let id = $(this).parent().parent().children("td:first").text();
                swal({
                        title: "确定删除吗？",
                        text: "删除后此记录将不存在！",
                        type: "warning",
                        showCancelButton: true,
                        confirmButtonColor: "#DD6B55",
                        confirmButtonText: "确定删除！",
                        cancelButtonText: "取消删除！",
                        closeOnConfirm: false,
                        closeOnCancel: false
                    },
                    function (isConfirm) {
                        if (isConfirm) {
                            $.ajax({
                                url: "<%=basePath%>doctorY/delDoctor",
                                type: "POST",
                                data: {
                                    id: id
                                }, dataType: "json",
                                success: function (data) {
                                    if (data) {
                                        swal({
                                            title: "删除成功"
                                        }, function () {
                                            location.reload()
                                        })
                                    } else {
                                        swal("数据跑丢了！");
                                    }
                                }
                            });
                        } else {
                            swal("您选择了取消！", " ", "error");
                        }
                    });

            })
            //更新确认
            $("#queren2").click(function () {
                array3[0] = $("#name2").val(); //姓名
                array3[1] = $("#yingchang2 :radio:checked").val();   //性别
                array3[2] = $("#age2").val(); //年龄
                array3[3] = $("#kezhong2 option:selected").val(); //所属科种
                array3[4] = $("#shengfeng2").val(); //身份证号
                array3[5] = $("#phone2").val();  //身份证号
                array3[6] = $("#jibie2 option:selected").val(); //级别
                array3[7] = $("#keshi2 option:selected").val(); //所属科室
                array3[8] = $("#school2").val();
                array3[9] = $("#dateRiqi2").val();

                console.log(array2[0] + " " + array3)

                if (pangduan2()) {
                    swal({
                            title: "确定更新吗？",
                            text: "此记录将被修改！",
                            type: "warning",
                            showCancelButton: true,
                            confirmButtonColor: "#DD6B55",
                            confirmButtonText: "确定！",
                            cancelButtonText: "取消！",
                            closeOnConfirm: false,
                            closeOnCancel: false
                        },
                        function (isConfirm) {
                            if (isConfirm) {
                                let doctorMsg = array3.join(",");
                                $.ajax({
                                    url: "<%=basePath%>doctorY/updDoctor",
                                    type: "POST",
                                    data: {
                                        id: array2[0],
                                        doctorMsg: doctorMsg
                                    }, dataType: "json",
                                    success: function (data) {
                                        if (data) {
                                            swal({
                                                title: "更新成功"
                                            }, function () {
                                                $("#yingchang2").hide()
                                                location.reload()
                                            })
                                        } else {
                                            swal("数据飘走了")
                                        }
                                    }
                                });
                            } else {
                                swal("数据飘走了!")
                            }
                        });

                }

            });
            //插入
            $("#queren").click(function () {

                array[0] = $("#name").val(); //姓名
                array[1] = $("#yingchang :radio:checked").val();   //性别
                array[2] = $("#age").val(); //年龄
                array[3] = $("#kezhong option:selected").val(); //所属科种
                array[4] = $("#shengfeng").val(); //身份证号
                array[5] = $("#phone").val();  //身份证号
                array[6] = $("#jibie option:selected").val(); //级别
                array[7] = $("#keshi option:selected").val(); //所属科室
                array[8] = $("#school").val();
                array[9] = $("#dateRiqi").val();

                if (pangduan()) {
                    let doctorMsg = array.join(",");
                    $.ajax({
                        url: "<%=basePath%>doctorY/addDoctor",
                        type: "POST",
                        data: {
                            doctorMsg: doctorMsg
                        },
                        dataType: "json",
                        success: function (data) {
                            if (data) {
                                swal({
                                    title: "新增成功"
                                }, function () {
                                    $("#yingchang").hide();
                                    location.reload()
                                })
                            } else {
                                swal("数据跑丢了！");
                                $("#yingchang").hide();
                            }
                        }
                    });
                }
            });
        });

        //非空判断函数
        function pangduan() {
            if (array[0].toString().trim().length == 0) {
                swal("姓名不能为空!");
                return false;
            } else if (isNaN(array[2]) || array[2].toString().trim().length == 0) {
                swal("年龄格式错误");
                return false;
            } else if (array[4].toString().trim().length != 18) {
                swal("身份证号不能小于18位");
                return false;
            } else if (array[5].toString().trim().length != 11) {
                swal("电话格式不正确");
                return false;
            } else if (array[8].toString().trim().length == 0) {
                swal("请填写毕业学校!");
                return false;
            } else if (array[9].toString().trim().length == 0) {
                swal("请填写日期!");
                return false;
            } else {
                return true
            }
        }

        //非空判断函数
        function pangduan2() {
            if (array3[0].toString().trim().length == 0) {
                swal("姓名不能为空!");
                return false;
            } else if (isNaN(array3[2]) || array3[2].toString().trim().length == 0) {
                swal("年龄格式错误");
                return false;
            } else if (array3[4].toString().trim().length != 18) {
                swal("身份证号不能小于18位");
                return false;
            } else if (array3[5].toString().trim().length != 11) {
                swal("电话格式不正确");
                return false;
            } else if (array3[8].toString().trim().length == 0) {
                swal("请填写毕业学校!");
                return false;
            } else if (array3[9].toString().trim().length == 0) {
                swal("请填写日期!");
                return false;
            } else {
                return true
            }
        }

        function qingkong() {
            $("#name").val(""); //姓名
            $(".sex:radio:checked").val("");   //性别
            $("#age").val(""); //年龄
            $("#shengfeng").val(""); //身份证号
            $("#phone").val("");  //身份证号
            $("#school").val("");
            $("#dateRiqi").val("");
        }

        function pb(doctorId, dept, type) {
            console.log(doctorId, dept, type)
            let types = 1;
            if (type == '普通医生') {
                types = 2;
            }
            console.log(types)
            swal({
                title: "<small>请选择日期</small>",
                text:
                    "<input type='date' id='rq'>"
                ,
                html: true,
                type: "prompt",
                showConfirmButton: true,
                confirmButtonText: "确定",
                showCancelButton: true,
                cancelButtonText: "取消"
            }, function (isConfirm) {
                if (isConfirm) {
                    let rq = document.getElementById('rq').value;  //上班日期
                    console.log(rq)
                    $.ajax({
                        url: "http://localhost:8080/doctorY/insertDuty",
                        type: "post",
                        data: {
                            doctorId: doctorId,
                            dept: dept,
                            date: rq,
                            type: types
                        },
                        dataType: "json",
                        success: function (data) {
                            if (data == true) {
                                swal({
                                    title: "排班成功!",
                                    type: "warning",
                                    confirmButtonText: "确定！"
                                }, function () {
                                    location.reload()
                                })
                            } else {
                                swal("排班失败!!!")
                            }
                        }
                    })
                }
            });
        }
</script>
